package com.wngbms.aop.dynamicproxy;

import com.wngbms.aop.staticproxy.DefaultEchoService;
import com.wngbms.aop.staticproxy.EchoService;

import java.lang.reflect.Proxy;

public class DynamicProxyDemo {

    public static void main(String[] args) {

        EchoService echoService = new DefaultEchoService();
        EchoServiceInvocation echoServiceInvocation = new EchoServiceInvocation(echoService);

        Object proxy = Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), new Class[]{EchoService.class}, echoServiceInvocation);
        EchoService destService = (EchoService) proxy;

        System.out.println(destService.getClass().getConstructors()[0]);
        System.out.println(destService.getClass().getSuperclass());
        System.out.println(destService.getClass().getInterfaces()[0]);
        System.out.println(destService.getClass());
        System.out.println(destService.echo("wngbms"));
    }

}
